use std::{io, cmp::Ordering};
use rand::{thread_rng, Rng};

fn main() {
    println!("猜数！");
    let secret_number = thread_rng().gen_range(1..101);

    loop {
        println!("猜一个数字");
        let mut guess = String::new();
        match io::stdin().read_line(&mut guess) {
            Ok(_) => print!(""),
            Err(_) => println!("无法获取输入")
        };
        println!("你猜的数字是：{}", guess);
        let guess:u32 = match guess.trim().parse(){
            Ok(num) => num,
            Err(_) => {
                println!("请输入数字");
                continue;
            }
        };
        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}
